//
//  WinkAlertView.m
//  MooreDoll
//
//  Created by 郭景豪 on 2014/11/26.
//  Copyright (c) 2014年 Tank. All rights reserved.
//

#import "WinkAlertView.h"

@implementation WinkAlertView
//包成method
+(void)_showAlertViewWithTitle:(NSString*)title content:(NSString*)content cancelButtonTitle:(NSString *)cancelButtonTitle showTime:(float)showTime{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:content
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle  //cancel按鈕文字的設定
                                          otherButtonTitles: nil]; // 設定其他按鈕title
    // 如果要多個其他按鈕 >> otherButtonTitles: @"check1", @"check2", nil];
    [alert setTag:0];
    [alert show];  // 把alert這個物件秀出來
    
    //2秒後關alert view
    double delayInSeconds = showTime;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        if (showTime != 0.0) {
            [alert dismissWithClickedButtonIndex:0 animated:NO];
        }
    });
}
+(void)_showAlertViewWithTitle:(NSString*)title content:(NSString*)content cancelButtonTitle:(NSString *)cancelButtonTitle otherButtonTitle:(NSString *)otherButtonTitle showTime:(float)showTime{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:content
                                                   delegate:nil
                                          cancelButtonTitle:cancelButtonTitle  //cancel按鈕文字的設定
                                          otherButtonTitles:otherButtonTitle, nil]; // 設定其他按鈕title
    // 如果要多個其他按鈕 >> otherButtonTitles: @"check1", @"check2", nil];
    [alert setTag:0];
    [alert show];  // 把alert這個物件秀出來
    
    //2秒後關alert view
    double delayInSeconds = showTime;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        if (showTime != 0.0) {
            [alert dismissWithClickedButtonIndex:0 animated:NO];
        }
    });
}

+(void)_showAlertViewHaveDelegateWithTitle:(NSString*)title content:(NSString*)content cancelButtonTitle:(NSString *)cancelButtonTitle showTime:(float)showTime delegate:(id)viewController
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
                                                    message:content
                                                   delegate:viewController
                                          cancelButtonTitle:cancelButtonTitle  //cancel按鈕文字的設定
                                          otherButtonTitles: nil]; // 設定其他按鈕title
    // 如果要多個其他按鈕 >> otherButtonTitles: @"check1", @"check2", nil];
    [alert setTag:0];
    [alert show];  // 把alert這個物件秀出來
    
    //2秒後關alert view
    double delayInSeconds = showTime;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        if (showTime != 0.0) {
            [alert dismissWithClickedButtonIndex:0 animated:NO];
        }
    });
}

@end
